package huawei.js2025;

import java.sql.SQLOutput;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;

/**
 * 简易内存池
 */
public class Question43 {

    public static class NeiCun implements Comparable<NeiCun> {
        private int start;
        private int end;

        public NeiCun(int start, int end) {
            this.start = start;
            this.end = end;
        }


        @Override
        public int compareTo(NeiCun o) {
            return this.start - o.start;
        }
    }

    public static int usedSize = 0;

    public static LinkedList<NeiCun> used = new LinkedList<>();

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        sc.nextLine();


        int lastReq = -1;
        for (int i = 0; i < N; i++) {
            String[] operations = sc.nextLine().split("=");
            if ("REQUEST".equals(operations[0])) {
                int size = Integer.parseInt(operations[1]);
                lastReq = req(size);
            } else {
                int index = Integer.parseInt(operations[1]);
                rel(index);
                lastReq = -1;
            }
        }

        if (lastReq != -1) {
            System.out.println(lastReq);
        }
    }

    // 分配地址
    public static Integer req(int size) {
        if (size == 0 || 100 - usedSize < size) {
            System.out.println("error");
            return -1;
        }

        if (used.isEmpty()) {
            used.add(new NeiCun(0, size));
            usedSize += size;
            return 0;
        }

        // 如果0开始能满足
        NeiCun neiCun = used.get(0);
        if (neiCun.start != 0) {
            int len = neiCun.start;
            if (len >= size) {
                used.addFirst(new NeiCun(0, size));
                usedSize += size;
                return 0;
            }
        }

        for (int i = 0; i < used.size() - 1; i++) {
            int s = used.get(i).end;
            int e = used.get(i + 1).start;
            int len = e - s;
            if (len >= size) {
                used.add(new NeiCun(s, size + s));
                usedSize += size;
                Collections.sort(used); // 排序
                return s;
            }
        }

        // 如果末尾还能插入
        if (100 - used.getLast().end >= size) {
            used.addLast(new NeiCun(used.getLast().end,  used.getLast().end + size));
            usedSize += size;
            return used.getLast().start;
        }

        // 分配不到空间
        System.out.println("error");
        return -1;
    }

    // 释放空间
    public static void rel (int i) {
        boolean is = false;
        for (int j = 0; j < used.size(); j++) {
            if (used.get(j).start == i) {
                NeiCun remove = used.remove(j);
                usedSize -= (remove.end - remove.start);
                is = true;
                break;
            }
        }

        // 释放不存在的地址
        if (!is) {
            System.out.println("error");
        }
    }
}
